package com.ruoyi.project.system.hotword.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.hotword.domain.HotWord;
import com.ruoyi.project.system.hotword.service.IHotWordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 热词Controller
 * 
 * @author LCL
 * @date 2020-06-19
 */
@Controller
@RequestMapping("/system/hotword")
public class HotWordController extends BaseController
{
    private String prefix = "system/hotword";

    @Autowired
    private IHotWordService hotWordService;

    @RequiresPermissions("system:hotword:view")
    @GetMapping()
    public String hotword()
    {
        return prefix + "/hotword";
    }

    /**
     * 查询热词列表
     */
    @RequiresPermissions("system:hotword:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HotWord hotWord)
    {
        startPage();
        List<HotWord> list = hotWordService.selectHotWordList(hotWord);
        return getDataTable(list);
    }

    /**
     * 导出热词列表
     */
    @RequiresPermissions("system:hotword:export")
    @Log(title = "热词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HotWord hotWord)
    {
        List<HotWord> list = hotWordService.selectHotWordList(hotWord);
        ExcelUtil<HotWord> util = new ExcelUtil<HotWord>(HotWord.class);
        return util.exportExcel(list, "hotword");
    }

    /**
     * 新增热词
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存热词
     */
    @RequiresPermissions("system:hotword:add")
    @Log(title = "热词", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HotWord hotWord)
    {
        return toAjax(hotWordService.insertHotWord(hotWord));
    }

    /**
     * 修改热词
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        HotWord hotWord = hotWordService.selectHotWordById(id);
        mmap.put("hotWord", hotWord);
        return prefix + "/edit";
    }

    /**
     * 修改保存热词
     */
    @RequiresPermissions("system:hotword:edit")
    @Log(title = "热词", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HotWord hotWord)
    {
        return toAjax(hotWordService.updateHotWord(hotWord));
    }

    /**
     * 删除热词
     */
    @RequiresPermissions("system:hotword:remove")
    @Log(title = "热词", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hotWordService.deleteHotWordByIds(ids));
    }
}
